package com.msb.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.msb.common.vo.CommonPageReq;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.Query;

import com.msb.mall.core.dao.ware.WareOrderTaskDao;
import com.msb.mall.core.entity.ware.WareOrderTaskEntity;
import com.msb.mall.ware.service.WareOrderTaskService;


@Service("wareOrderTaskService")
public class WareOrderTaskServiceImpl extends ServiceImpl<WareOrderTaskDao, WareOrderTaskEntity> implements WareOrderTaskService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WareOrderTaskEntity> page = this.page(
                new Query<WareOrderTaskEntity>().getPage(params),
                new QueryWrapper<WareOrderTaskEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageCondition(CommonPageReq<Map<String, Object>> req) {
        Page<WareOrderTaskEntity> page = new Page<>(req.getCurrPage(), req.getPageSize());

        Map<String, Object> param = req.getData();
        LambdaQueryWrapper<WareOrderTaskEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (param != null) {
            String key = (String) param.get("key");
            queryWrapper.like(StringUtils.isNotEmpty(key), WareOrderTaskEntity::getConsignee, key);
        }

        Page<WareOrderTaskEntity> wareOrderTaskEntityPage = baseMapper.selectPage(page, queryWrapper);
        return new PageUtils(wareOrderTaskEntityPage);
    }

}
